(() => {
    'use strict';
    // 取原型链上的toString
    const $toString = Function.toString;
    // 取方法名 reload
    const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)));
    const myToString = function () {
        return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this);
    };

    function set_native(func, key, value) {
        Object.defineProperty(func, key, {
            "enumerable": false,  // 不可枚举
            "configurable": true, // 可配置
            "writable": true, // 可写
            "value": value
        })
    }

    delete Function.prototype['toString'];// 删除原型链上的toString
    set_native(Function.prototype, "toString", myToString); // 自定义一个getter方法，其实就是一个hook
    //套个娃，保护一下我们定义的toString，避免js对toString再次toString，如：location.reload.toString.toString() 否则就暴露了
    set_native(Function.prototype.toString, myFunction_toString_symbol, "function toString() { [native code] }");
    globalThis.safefunction = (func) => {
        set_native(func, myFunction_toString_symbol, `function ${myFunction_toString_symbol, func.name || ''}() { [native code] }`);
    }; //导出函数到globalThis，更改原型上的toSting为自己的toString。这个方法相当于过掉func的toString检测点
}).call(globalThis);
(() => {
    const origin_log = console.log;
    console_log = function () {
        return origin_log(...arguments)
    }
})();

function lrqproxy(obj, name) {
    return new Proxy(obj, {
        get(target, propKey, receiver) { //拦截对象属性的读取，比如proxy.foo和proxy['foo']。
            let temp = Reflect.get(target, propKey, receiver);
            if (propKey.toString() !== "attachEvent" && propKey.toString() !== "stack" && propKey.toString() !== 'Symbol(Symbol.toPrimitive)') {
                console_log(`${name} -> get ${propKey.toString()} return -> ${temp}`);
            }
            if (typeof temp == 'object') {
                temp = lrqproxy(temp, name + " => " + propKey)
            }
            return temp;
        },
        set(target, propKey, value, receiver) { //拦截对象属性的设置，比如proxy.foo = v或proxy['foo'] = v，返回一个布尔值。
            const temp = Reflect.set(target, propKey, value, receiver);
            if (propKey.toString() !== "D" && propKey.toString() !== "B" && propKey.toString() !== "stack") {
                //console_log(`${name} -> set ${propKey.toString()} value -> ${value}`);
                console_log(`${name} -> set ${propKey} value -> ${value}`);
            }
            //console_log(`${name} -> set ${propKey} value -> ${value}`);
            return temp;
        },
        has(target, propKey) { //拦截propKey in proxy的操作，返回一个布尔值。
            const temp = Reflect.has(target, propKey);
            console_log(`${name} -> has ${propKey.toString()} return -> ${temp}`);
            return temp;
        },
        deleteProperty(target, propKey) { //拦截delete proxy[propKey]的操作，返回一个布尔值。
            const temp = Reflect.deleteProperty(target, propKey);
            console_log(`${name} -> deleteProperty ${propKey}`);
            return temp;
        },
        ownKeys(target) {
            const keys = Reflect.ownKeys(target);

            // 将 keys 数组转换为字符串数组，以便安全地进行打印和返回
            const stringKeys = keys.map(key => {
                if (typeof key === 'symbol') {
                    return key.description ? `Symbol(${key.description})` : 'Symbol()';
                } else {
                    return key.toString();
                }
            });

            console_log(`${name} -> ownKeys ${stringKeys}`); // 打印转换为字符串后的 keys

            return keys; // 返回字符串数组
        },
        //加的
        getOwnPropertyDescriptor(target, propKey) { //拦截Object.getOwnPropertyDescriptor(proxy, propKey)，返回属性的描述对象。
            const descriptor = Reflect.getOwnPropertyDescriptor(target, propKey);
            // console_log(`${name} -> getOwnPropertyDescriptor ${propKey.toString()} return ->`, descriptor);
            return descriptor;
        },
        defineProperty(target, propKey, propDesc) { //拦截Object.defineProperty(proxy, propKey, propDesc）、Object.defineProperties(proxy, propDescs)，返回一个布尔值。
            const success = Reflect.defineProperty(target, propKey, propDesc);
            console_log(`${name} -> defineProperty ${propKey.toString()} descriptor ->`, propDesc, 'success ->', success);
            return success;
        },
        preventExtensions(target) { //拦截Object.preventExtensions(proxy)，返回一个布尔值。
            const success = Reflect.preventExtensions(target);
            console_log(`${name} -> preventExtensions success ->`, success);
            return success;
        },
        getPrototypeOf(target) { //拦截Object.getPrototypeOf(proxy)，返回一个对象。
            const prototype = Reflect.getPrototypeOf(target);
            console_log(`${name} -> getPrototypeOf return ->`, prototype);
            return prototype;
        },
        isExtensible(target) { //拦截Object.isExtensible(proxy)，返回一个布尔值。
            const extensible = Reflect.isExtensible(target);
            console_log(`${name} -> isExtensible return ->`, extensible);
            return extensible;
        },
        setPrototypeOf(target, proto) { //拦截Object.setPrototypeOf(proxy, proto)，返回一个布尔值。如果目标对象是函数，那么还有两种额外操作可以拦截。
            const success = Reflect.setPrototypeOf(target, proto);
            console_log(`${name} -> setPrototypeOf proto ->`, proto, 'success ->', success);
            return success;
        },
        apply(target, object, args) { //拦截 Proxy 实例作为函数调用的操作，比如proxy(...args)、proxy.call(object, ...args)、proxy.apply(...)。
            console_log(`${name} -> apply object ->`, object, 'args ->', args);
            const result = Reflect.apply(target, object, args);
            console_log(`${name} -> apply result ->`, result);
            return result;
        },
        construct(target, args) { //拦截 Proxy 实例作为构造函数调用的操作，比如new proxy(...args)。
            console_log(`${name} -> construct args ->`, args);
            const result = Reflect.construct(target, args);
            console_log(`${name} -> construct result ->`, result);
            return result;
        }
    })
}

window = globalThis;
window.isNaN = function isNaN(arg) {
    console_log("isNaN", arg);
};safefunction(isNaN)
document = {};
canvas = lrqproxy({
    [Symbol.toStringTag]: "HTMLCanvasElement"
}, "canvas");
safefunction(canvas)
webgl = lrqproxy({
    [Symbol.toStringTag]: "WebGLRenderingContext"
}, "webgl");
safefunction(webgl)
canvas.getContext = function getContext(arg) {
    console_log("canvas.getContext", arg);
    if (arg == "webgl") {
        return webgl
    }
};
safefunction(canvas.getContext)
document.createElement = function (arg) {
    console_log("document.createElement", arg);
    if (arg == "canvas") {
        return canvas
    }
};
safefunction(document.createElement);
document.cookie = 'abRequestId=a43ad666-a02e-58ca-9118-2e1060b1acdc; webBuild=4.70.2; xsecappid=xhs-pc-web; a1=197cfad4787s2rvodll9lz3rs9y4gbltcy9wx28xi50000828195; webId=34e7f10a591d745df3ecbf326332c90c; gid=yjWSi0fKKKSyyjWSi0f4WvJYYWMJFhlf11j1jC3uqFMjvE284kD19C888YJYyj28if22yjfY; loadts=1751536096555; unread={%22ub%22:%2268652e6f000000002400cfe2%22%2C%22ue%22:%226861e47e0000000015023f03%22%2C%22uc%22:29}; websectiga=7750c37de43b7be9de8ed9ff8ea0e576519e8cd2157322eb972ecb429a7735d4; sec_poison_id=466cba50-131d-4362-a083-b6dd02801c72';

document.documentElement = lrqproxy({
    [Symbol.toStringTag]: 'HTMLHtmlElement'
}, "document.documentElement")

Navigator = function Navigator() {
};
safefunction(Navigator)
lrqproxy(Navigator, "Navigator")
navigator = Object.create(Navigator.prototype)

navigator = {
    [Symbol.toStringTag]: 'Navigator',
}
navigator.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36'
navigator.vendor = 'Google Inc.'
navigator.platform = 'MacIntel'
navigator.language = 'zh-CN'
navigator.hardwareConcurrency = 4
navigator.appName = "Netscape"
navigator.appVersion = "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
navigator.connect = lrqproxy({}, "navigator.connect")
navigator.userAgentData = {
    "brands": [
        {
            "brand": "Google Chrome",
            "version": "137"
        },
        {
            "brand": "Chromium",
            "version": "137"
        },
        {
            "brand": "Not/A)Brand",
            "version": "24"
        }
    ],
    "mobile": false,
    "platform": "macOS"
}
navigator.webdriver = false
navigator.storage = lrqproxy({
    [Symbol.toStringTag]: 'StorageManager'
}, "navigator.storage");
safefunction(navigator.storage)
navigator.connection = lrqproxy({
    rtt: 50,
    [Symbol.toStringTag]: 'NetworkInformation'
}, "navigator.connection")
navigator.__proto__ = Navigator.prototype
Screen = function Screen(){};safefunction(Screen);

lrqproxy( Screen,"Screen")
screen = {
    availWidth: 1440,
    availHeight: 900,
    width: 1440,
    height: 900,
    colorDepth: 24,
    pixelDepth: 24,
    orientation: {
        angle: 0,
        type: "landscape-primary",
        onchange: null
    },
    [Symbol.toStringTag]: "Screen"
}
location = {
    "ancestorOrigins": {},
    "href": "https://www.douyin.com/user/MS4wLjABAAAAtw6AwaGxwUE4kc4VAwLkrZ2yHRRB-oCa9-h5LSP1nRg?from_tab_name=main",
    "origin": "https://www.douyin.com",
    "protocol": "https:",
    "host": "www.douyin.com",
    "hostname": "www.douyin.com",
    "port": "",
    "pathname": "/user/MS4wLjABAAAAtw6AwaGxwUE4kc4VAwLkrZ2yHRRB-oCa9-h5LSP1nRg",
    "search": "?from_tab_name=main",
    "hash": "",
    [Symbol.toStringTag]: "Location"
}
history = {
    [Symbol.toStringTag]:"History"
}
localStorage = {
    "sdt_source_storage_key": '{"xhsTokenUrl":"https://fe-static.xhscdn.com/as/v1/3e44/public/bf7d4e32677698655a5cadc581fd09b3.js","extraInfo":"","validate":false,"signVersion":"1","desVersion":"2","commonPatch":["/fe_api/burdock/v2/note/post","/api/sns/web/v1/comment/post","/api/sns/web/v1/note/like","/api/sns/web/v1/note/collect","/api/sns/web/v1/user/follow","/api/sns/web/v1/feed","/api/sns/web/v1/login/activate","/api/sns/web/v1/note/metrics_report","/api/redcaptcha","/api/store/jpd/main","/phoenix/api/strategy/getAppStrategy","/web_api/sns/v2/note"],"signUrl":"https://fe-static.xhscdn.com/as/v1/3e44/public/04b29480233f4def5c875875b6bdc3b1.js","url":"https://fe-static.xhscdn.com/as/v1/f218/a8/public/0666f0acdeed38d4cd9084ade1739498.js","reportUrl":"/api/sec/v1/shield/webprofile"}',
    [Symbol.toStringTag]: "Storage"
};
sessionStorage = {
    [Symbol.toStringTag]: "Storage"
}
localStorage.getItem = function getItem(key) {
    return localStorage[key];
};safefunction(localStorage.getItem)
window = lrqproxy(window, "window");
document = lrqproxy(document, "document");
navigator = lrqproxy(navigator, "navigator");
location = lrqproxy(location, "location");
screen = lrqproxy(screen, "screen");
history = lrqproxy(history, "history");
localStorage = lrqproxy(localStorage, "localStorage");
sessionStorage = lrqproxy(sessionStorage, "sessionStorage");